package com.black.play.component.base;

import com.black.play.common.LinkAble;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.io.IOException;

/**
 * @author ylx
 */
@Setter
@Getter
public class AppLink extends JLabel implements LinkAble {
    public static final int REMOTE_URL = 0;
    public static final int LOCAL_PATH = 1;
    public static final String template = "<html><u>%s</u></html>";
    private String route;
    private int type;

    public AppLink(String route) {
        this(route, LOCAL_PATH);
    }

    public AppLink(String route, int type) {
        super(String.format(template, route));
        this.type = type;
    }

    public void open() throws IOException {
        if (type == REMOTE_URL) {
            browse(this.route);
        } else {
            open(this.route);
        }
    }
}
